<?php

namespace App\Admin\Controllers;

use Illuminate\Http\Request;

class LoginController extends Controller
{
	/**
	 * [index description]
	 * @return [type] [description]
	 */
	public function index()
	{
		return view('admin.login.index');
	}

	/**
	 * [login description]
	 * @return [type] [description]
	 */
	public function login()
	{
		$this->validate(request(), [
				'name' => 'required',
				'password' => 'required',
			]);
		$user = request(['name', 'password']);
		if (\Auth::guard('admin')->attempt($user)) {

			return redirect('/admin/home');
		}

		return \Redirect::back()->withErrors('用户名或密码不匹配');
	}

	/**
	 * [logout description]
	 * @return [type] [description]
	 */
	public function logout()
	{
		\Auth::guard('admin')->logout();
		return redirect('/admin/login');
	}
}